/*
Write declarations for the following:
(1) a function taking arguments of type pointer to character and refrence to integer and returning no value;
(2) a pointer to such a function;
(3) a function taking such a pointer as an argument;
(4) a function returning such a pointer.
Write the definition of a function that takes such a pointer as an argument and returns its argument as the return value.  Hint: use typedef*/

#include <iostream>
using namespace std;

//(1) a function taking arguments of type pointer to character and refrence to integer and returning no value;
void func_1(char*,int&);        //函数的声明

//(2) a pointer to such a function;
void (*func_p)(char*,int&) = func_1;    //指针变量的定义
// void (*func_p)(char*,int&) = &func_1; 有无地址符都可！

typedef void (*FP)(char*,int&);     //数据类型FP:指向函数的指针

//(3) a function taking such a pointer as an argument;
void func_2(FP);    //函数的声明
// void func_2(void (*func_p)(char*,int&)); 

//(4) a function returning such a pointer.
FP func_3();
//注意：void (*)(char*,int&) func_3()是无法编译的！

//(5)a function that takes such a pointer as an argument and returns its argument as the return value.
FP func_4(FP fp){
    cout<<"Now I am in func_4!" <<endl;
    return fp;
}

int main(int argc, char const *argv[])
{
    char ch='s';
    int i=2;
    func_1(&ch,i);
    func_4(func_3());
    return 0;
}


void func_1(char* p,int& n){        //函数的定义
    cout<<"Now I am in func_1!" <<endl;
    cout<<"The char is:"<<*p<<"\tThe int is:"<<n<<endl;
}

void func_2(void (*func_p)(char*,int&)){    //函数的定义
    cout<<"Now I am in func_2!" <<endl;
}

FP func_3(){        //函数的定义
    cout<<"Now I am in func_3!" <<endl;
    return func_p;
}